package com.shop.mall.utils;

import java.io.FileInputStream;
import java.util.Properties;

/**
 * @author admin
 * @version 1.0
 * @date 2019/4/23
 */
public class PropertiesUtil {
    public static String getProperties(String propertyName) {
        String value = "";
        Properties pro = new Properties();
        try {
            String path = PropertiesUtil.class.getResource("/").getPath();//得到工程名WEB-INF/classes/路径
            path = path.substring(1, path.indexOf("classes"));//从路径字符串中取出工程路径
            System.out.println(path);
            pro.load(new FileInputStream(path + "config/db.properties"));

            value = pro.getProperty(propertyName);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return value;
    }

    public static void main(String[] args) {
        System.out.println(getProperties("ip"));
    }
}
